Skip to content

fix(turn): send the authenticated Allocate retry under a fresh random id - #332

Open
mnaza wants to merge 1 commit into
webrtc-rs:masterfrom
mnaza:allocate-random-retry-id
Open

mnaza wants to merge 1 commit into
webrtc-rs:masterfrom
mnaza:allocate-random-retry-id

Conversation

@mnaza

@mnaza mnaza commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #281, as agreed in its review thread.

The authenticated Allocate retry after a 401 went out under the anonymous request's id with
its last byte bumped. RFC 8489 §6 wants every new transaction under a fresh random 96-bit id,
and the retry is a new transaction. The predictable id was a small risk on its own, but it also
made allocate() foretell its own retry id, which is why #281 had to special-case the timeout
and the nonce-less error exit.

What changes:

  • The retry carries TransactionId::new(), like every other request.
  • TransactionType::AllocateRequest remembers the id allocate() returned next to the nonce,
    and the response, error and timeout handlers report that id.
  • allocate() returns the anonymous request's own id, so authenticated_allocate_id() and both
    special cases from fix(turn): report an Allocate timeout under the id allocate() returned #281 go away.
  • Callers see no difference: every event about an allocation still names the id allocate()
    handed out, which is what webrtc's relayer and the examples match on.

Testing:

  • New test: answer the anonymous Allocate with a 401 carrying nonce and realm, read the retry
    off the wire, and assert its id differs from the anonymous one in more than the last byte.
    Then answer it with a success, a 403 and silence, and assert each event names the id
    allocate() returned. It was red before the change: the first 11 bytes matched.
  • The fix(turn): report an Allocate timeout under the id allocate() returned #281 tests pass unchanged. Two older tests that built TransactionType::AllocateRequest
    directly were updated to the struct variant.
  • rtc-turn: 52 lib tests pass on current master. cargo fmt is clean, and so is
    cargo clippy -p rtc-turn --lib -D warnings.
  • Against a real coturn 4.6 (lt-cred-mech, loopback), examples/turn_client_udp: coturn logs
    the 401 on the anonymous Allocate, then ALLOCATE processed, success on the random-id retry,
    and the example's assert_eq!(tid, allocate_tid) holds. From webrtc with this commit in the
    submodule, turn_over_tcp and turn_credential_rotation both pass against the same server.

The retry after a 401 went out under the anonymous request's id with its
last byte bumped. RFC 8489 §6 wants every new transaction under a fresh,
cryptographically random 96-bit id, and the retry is a new transaction.
The risk was small — whoever could predict the id had seen the first
request — but the rule also forced allocate() to foretell its own retry,
and webrtc-rs#281 had to special-case the timeout and the error exit so that they
named that foretold id rather than the one on the wire.

The retry now carries TransactionId::new(), as every other request does,
and the transaction remembers which allocation it belongs to:
TransactionType::AllocateRequest holds the id allocate() returned next to
the nonce, and the response, error and timeout handlers report that id.
allocate() returns the anonymous request's own id, so an error or a
timeout on the first request names the wire id as it is, and
authenticated_allocate_id() and both special cases go away. Nothing
visible to a caller changes: every event about an allocation still names
the id allocate() handed out, which is what webrtc's relayer and the
examples match on.

The test drives a 401 with nonce and realm, reads the retry off the wire
and asserts its id differs from the anonymous one in more than its last
byte; then answers it with a success, with a 403, and with nothing, and
asserts each event names the id allocate() returned. The webrtc-rs#281 tests pass
unchanged.

Follow-up to webrtc-rs#281, as discussed there.
@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.43590% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.54%. Comparing base (0fbcaa7) to head (e683577).

Files with missing lines Patch % Lines
rtc-turn/src/client/client_test.rs 97.36% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #332      +/-   ##
==========================================
+ Coverage   88.47%   88.54%   +0.06%     
==========================================
  Files         512      512              
  Lines       75483    75589     +106     
==========================================
+ Hits        66787    66929     +142     
+ Misses       8696     8660      -36     
Flag Coverage Δ
aws-lc-rs 88.25% <97.43%> (+0.01%) ⬆️
ring 88.54% <97.43%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant